from flask import Blueprint, jsonify, request
import os
from comm import get_data
from db import db1

bp_work = Blueprint("work", __name__)

llllo
# @bp_work.route('/demp', methods=['POST', 'GET'])
# def demp():
#     if request.method == 'POST':
#         data = get_data()
#         sql = "insert into demp values (0,'%s',%d)" % (data['name'], int(data['count']))
#         db1.insert(sql)
#         return 'ok'
#     else:
#         sql = "select * from demp"
#         res = db1.findall(sql)
#         return jsonify({'code': 200, 'list': res})
#
#
# @bp_work.route('/staff', methods=['POST', 'GET'])
# def staff():
#     if request.method == 'POST':
#         data = get_data()
#         sql = "insert into staff values (0,'%s','%s',%d,%d)" % (
#             data['name'], data['sex'], int(data['money']), int(data['cid']))
#         db1.insert(sql)
#         sql1 = 'select count from demp where id=%d' % (int(data['cid']))
#         res = db1.find(sql1)
#         total = int(res['count']) + 1
#         sql2 = 'update demp set count=%d where id=%d' % (total, int(data['cid']))
#         db1.insert(sql2)
#         return jsonify({'code': 200})


# 照片上传
# 照片上传
@bp_work.route('/jpgupload', methods=['POST'])
def jpgupload():
    file = request.files['file']
    file.save(os.path.join('./static/upload/', file.filename))
    return jsonify({'code': 200, 'pic': file.filename})


# 视频上传
@bp_work.route('/vedioupload', methods=['POST'])
def vedioupload():
    file = request.files['file']
    id = request.form['id']
    path = './static/upload/' + str(id)
    if not os.path.exists(path):
        os.mkdir(path)
    file.save(os.path.join(path, file.filename))
    # 返回结果
    return jsonify({"code": 200, 'url': '/static/upload' + '/' + str(id) + '/' + file.filename})


# 添加接口
@bp_work.route('/add', methods=['POST', 'GET'])
def add():
    pass
